package top.tresman.cxxcommon.entity;

import lombok.Data;
import top.tresman.cxxcommon.entity.constants.ErrorCodeEnum;

@Data
public class Result<T> {

    private Integer code;

    private String message;

    private T data;

    public Result(ErrorCodeEnum codeEnum, String message, T data) {
        this.code = codeEnum.getCode();
        this.message = message;
        this.data = data;
    }

    public Result() {
    }

    public Result(ErrorCodeEnum codeEnum, String message) {
        this.code = codeEnum.getCode();
        this.message = message;
    }

    public static Result<Void> success() {
        return new Result<>(ErrorCodeEnum.OK, "success");
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(ErrorCodeEnum.OK, "success", data);
    }

    public static <T> Result<T> error(ErrorCodeEnum codeEnum, String message) {
        return new Result<>(codeEnum, message);
    }
}
